package top.chendawei.util.params;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.sql.Timestamp;

@ToString
@Builder
@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor
public class ResultMessage<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    public static int OK = 200;
    public static int FAIL = -1;
    private static String SUCCESS = "操作成功";
    private static String ERROR = "操作失败";
    protected int code;
    private String message;
    private T data;
    private Timestamp timestamp;

    public static <T> ResultMessage<T> success() {
        return success(OK, SUCCESS, null);
    }

    public static <T> ResultMessage<T> success(int status, String message, T data) {
        return create(status, message, data, null);
    }

    public static <T> ResultMessage<T> success(T data) {
        return success(OK, SUCCESS, data);
    }

    public static <T> ResultMessage<T> create(int code, String message, T data, String exception) {
        return (ResultMessage<T>) ResultMessage.builder().data(data).message(message).code(code).build();
    }

    public static <T> ResultMessage<T> error() {
        return error(FAIL, ERROR, null);
    }

    public static <T> ResultMessage<T> error(String message) {
        return error(FAIL, message, null);
    }

    public static <T> ResultMessage<T> error(int code, String message) {
        return error(code, message, null);
    }

    public static <T> ResultMessage<T> error(int code, String message, T data) {
        return error(code, message, data, null);
    }

    public static <T> ResultMessage<T> error(int code, String message, T data, String exception) {
        return create(code, message, data, exception);
    }
}
